<template>
  <div class="content-block block-1">
    <div class="info-head">{{ title }}</div>
    <div class="info-content padding">
      <el-table
        v-loading="loading" class="table"
        :data="lists" height="300px"
        :header-cell-style="{
          backgroundColor: themeColor,
          color: 'white'
        }"
      >
        <el-table-column v-for="column in columns" :key="column.prop" v-bind="column"></el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
export default {
  name: 'grid-item-one',
  props: {
    title: String
  },
  data () {
    return {
      loading: false,
      lists: [],
      columns: [
        { label: '行业', prop: 'col1' },
        { label: '综合能源消费量（万吨标准煤）', prop: 'col2' },
        { label: '工业总产值（万元）', prop: 'col3' },
        { label: '用电量（万千瓦时）', prop: 'col4' },
        { label: '能源消费总量（万吨标准煤）', prop: 'col5' },
      ]
    }
  },
  computed: {
    themeColor () {
      return this.$store.state.user.theme
    },
    energyIndustry () {
      return this.$store.state.energyIndustry
    }
  },
  mounted () {
    this.getLists()
    this.$store.dispatch('GET_ENERGY_INDUSTRY')
  },
  methods: {
    getLists () {
      const rand = () => Math.round(Math.random() * 99 + 1)
      this.loading = true
      // TODO
      return new Promise((resolve) => {
        this.loading = false
        resolve()
        this.lists = this.energyIndustry.map(v => ({
          col1: v.name,
          col2: rand(),
          col3: rand(),
          col4: rand(),
          col5: rand()
        }))
      })
    }
  }
}
</script>

<style scoped>

</style>
